<?php

class BaseAction extends Action{

	protected  $cityid;

	protected  $cityname;

	protected  $cateid; 

	protected  $cityinfo;
	
	protected  $areaid;
	
	protected  $areainfo;

	protected  $uinfo;

	function __construct(){

		parent::__construct();


		 $data = array('top'=>'0','toptime'=>'0');
		 $nowtime = mktime();	//得到现在时间
		 M('Zhaopin')->where('status=1 and top>0 and toptime<'.mktime())->setField($data);  //超时下架
		
		
        $city = $_COOKIE['ddcitypinyinClient'];//从COOKEID里找到城市

		  if(isset($_GET['city'])){    //如果存在城市
				$city = $_GET['city'];
		 }  
		 
		 
		//广告位

		$adinfo =M('Ad')->where("endtime >".time())->select();

		$this->assign("adinfo",$adinfo);

		$cid = $_GET['cid'];

		$cityinfo = M('City')->where("pinyin='".$city."'")->find();
		
		if(!isset($cityinfo['id'])){ 
             $areainfo = M('Area')->where("pinyin='".$city."'")->find();
		}

		//搜索
		
		if(isset($_POST['search'])){
		$data['input_keywords']=$_POST['input_keywords'];
		header("Location: ".U('Search/index',array('keywords'=>$data['input_keywords'])));
		}
	
		
		//得到地区
		/*
		if(S('citym')){
            $citym = S('citym');
            
        }else{
			$char = 65;
			for($i=0;$i<26;$i++){
			 $citym[]['chr']= chr($char);
			 $char++;
			}
			
            foreach ($citym as $u => $k){
				
                $citym[$u]['city'] = M('City')->where("initial='".$k['chr']."' AND status=0")->select();
				
            }
			 S("citym",$citym,360); 
		}


		$this->assign('listm',$citym);
		*/
		if(S('citylist')){
            $citylist = S('citylist');
            
        }else{
            $Data=M('City');
            
            $temp=$Data->where('cid=0 AND status=0')->select();
            
            foreach ($temp as $v){
            
                $v['city'] = M('City')->where("cid=".$v['id']." AND status=0")->select();
            
                $citylist[]=$v;
            
            }
            S("citylist",$citylist,360); 
        }

		$this->assign('citylist',$citylist);

		//判断登录

		$this->uinfo = checkUserCookie();
		
		$this->assign("uinfo",$this->uinfo);

		$this->cityinfo = $cityinfo;
        if (!empty($cityinfo['id'])){
			$this->cityid = $cityinfo['id'];
		}else{
			$this->areaid = $areainfo['id'];
			$this->areainfo = $areainfo;
		}
		//$this->cityid = $cityinfo['id'];
		
		//$this->areaid = $areainfo['id'];
	
		if(empty($cid)){

		  $this->cateid =0;	

		}else{

		  $this->cateid = M('Category')->where("path='".$cid."'")->getField("id");

		}

		$this->assign("cateid",$this->cateid);

		$cate = M('Category')->select();

	    $config = M('Config')->where("id=1")->find();

	    $this->assign("config",$config);

		$this->assign("cate",$cate);

		$this->assign("city",$city);//城市目录
		
        if(isset($cityinfo)){
		   $this->assign("cityname",$cityinfo['city']);
		}else{
		   $this->assign("cityname",$areainfo['name']);
		}

        if(isMobile()){
            $this->assign("dev","phone");
        }else{
            $this->assign("dev","pc");
        }

	}



}

?>